package proxy01;

public class Test {
    public static void main(String [] args){


//        CompanyA companyA = new PersonA();
//        Proxy proxy = new Proxy();
//        proxy.setCompanyA(companyA);
//        proxy.sale("水");
//
//        CompanyB companyB = new PersonB();
//        Proxy proxyb = new Proxy();
//        proxyb.setCompanyB(companyB);
//        proxyb.saleb("水");

        //接口companyA，接口实现personA
        CompanyA companyA = new PersonA();
        //动态代理类dyproxy
        Dyproxy dyproxy=new Dyproxy();
        //将需要代理的接口companyA注入动态代理类
        dyproxy.setObject(companyA);
        //根据注入的接口类型生成代理实例并强转为接口A
        CompanyA proxyInstance= (CompanyA) dyproxy.getInstance();
        //此时调用接口A会执行动态代理的增强的接口方法
        proxyInstance.sale("水");

        CompanyB companyB = new PersonB();
        dyproxy.setObject(companyB);
        CompanyB proxyInstanceb= (CompanyB) dyproxy.getInstance();
        proxyInstanceb.saleb("水asd");



    }
}
